package com.wb3.meta.config;

import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author raopeng
 * @Description //TODO 鉴权配置
 * @Date 2022/4/1 17:14
 * @Param
 * @return
 **/
@Setter
@RefreshScope
@ConfigurationProperties(prefix = "meta.auth")
@Component
public class AuthProperties {
    /**
     * 是否开启鉴权，默认否
     */
    private boolean enable = false;

    /**
     * 不需要鉴权的url列表
     */
    private List<String> ignoreUrl = new ArrayList<>();


    /**
     * 监控中心和swagger须要访问的url
     */
    private static final String[] ENDPOINTS = {
            "/base/oauth/**",
            "/actuator/**",
            "/v2/api-docs/**",
            "/v2/api-docs-ext/**",
            "/swagger/api-docs",
            "/swagger-ui.html",
            "/doc.html",
            "/swagger-resources/**",
            "/webjars/**",
            "/druid/**",
            "/error/**",
            "/assets/**"
    };

    /**
     * 自定义getter方法，并将ENDPOINTS加入至忽略URL列表
     * @return List
     */
    public List<String> getIgnoreUrl() {
        Collections.addAll(ignoreUrl, ENDPOINTS);
        return ignoreUrl;
    }

    public Boolean getEnable() {
        return enable;
    }

}
